import React from 'react';
import { memoryUtils } from '../../utils/memoryUtils';
import { Redirect, Route, Switch  } from 'react-router-dom';
import { Layout } from 'antd';
import { Nav } from "../../components/left-nav/left-nav.js";
import { Head } from "../../components/header/header.js";
import { Home } from "../home/home.js";
import { Category } from "../category/category.js";
import { Product } from "../product/product.js";
import { Role } from "../role/role.js";
import { User } from "../user/user.js";
import { Bar } from "../charts/bar.js";
import { Line } from "../charts/line.js";
import { Pie } from "../charts/pie.js";
const { Footer, Sider, Content } = Layout;

export const Admin = () => {
    
    const user = memoryUtils.user;
    console.log(user);
    if(!user || !user.username) {
        return <Redirect to="/login"/>
    }

    return (
        <Layout style={{height: "100%"}}>
            <Sider>
                <Nav/>
            </Sider>
            <Layout>
                <Head>Header</Head>
                <Content style={{margin: 20, backgroundColor: "#fff"}}>
                    <Switch>
                        <Route path="/home" component={Home} />
                        <Route path="/category" component={Category} />
                        <Route path="/product" component={Product} />
                        <Route path="/role" component={Role} />
                        <Route path="/user" component={User} />
                        <Route path="/charts/bar" component={Bar} />
                        <Route path="/charts/line" component={Line} />
                        <Route path="/charts/pie" component={Pie} />
                        <Redirect to="/home"/>
                    </Switch>
                </Content>
                <Footer style={{textAlign: "center", color: "#ccc"}}>推荐使用谷歌浏览器，可以获得更加页面操作体验</Footer>
            </Layout>
        </Layout>
    )
}